<Table TItem="BindItem"
       IsPagination="true" PageItemsSource="@(new int[] { 2, 4 })"
       IsStriped="true" IsBordered="true" IsMultipleSelect="true"
       IsAutoRefresh="true" AutoRefreshInterval="2000"
       OnQueryAsync="@OnRefreshQueryAsync">
    <TableColumns>
        <TableColumn @bind-Field="@context.DateTime" Width="180" />
        <TableColumn @bind-Field="@context.Name" Width="100" />
        <TableColumn @bind-Field="@context.Address" />
        <TableColumn @bind-Field="@context.Count" />
        <TableColumn @bind-Field="@context.Complete">
            <Template Context="v">
                <Switch IsDisabled="true" Value="v.Value" ShowInnerText="true" OnInnerText="是" OffInnerText="否" />
            </Template>
        </TableColumn>
    </TableColumns>
</Table>

@code {
    private Task<QueryData<BindItem>> OnRefreshQueryAsync(QueryPageOptions options)
    {
        // 设置记录总数
        var total = AutoItems.Count();

        AutoItems.Insert(0, new BindItem()
        {
            Id = total++,
            Name = $"张三 {total:d4}",
            DateTime = DateTime.Now.AddDays(total - 1),
            Address = $"上海市普陀区金沙江路 {random.Next(1000, 2000)} 弄",
            Count = random.Next(1, 100),
            Complete = random.Next(1, 100) > 50,
            Education = random.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middel
        });

        if (AutoItems.Count > 10)
        {
            AutoItems.RemoveRange(10, 1);
            total = 10;
        }

        // 内存分页
        var items = AutoItems.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList();

        return Task.FromResult(new QueryData<BindItem>()
        {
            Items = items,
            TotalCount = total
        });
    }
}
